home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / VIEWS.ZIP;1 / CVDZIP.EXE / CVSKETCH.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-30  |  3.2 KB  |  172 lines

  1. /*
  2.     cvsketch.cpp
  3.  
  4.     Sketch pad example
  5.     
  6.     C++/Views 2.0 Demo
  7.     Copyright (c) 1992, by Liant Software Corp.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12. */
  13.  
  14. #include "cvsketch.h"
  15. #include "cvdemovw.h"
  16. #include "notifier.h"
  17. #include "port.h"
  18. #include "pen.h"
  19. #include "cvcolor.h"
  20. #include "pointrry.h"
  21.  
  22. defineClass(SketchView, VMdiView)
  23.  
  24. SketchView::SketchView()
  25. {
  26.     ;
  27. }
  28.  
  29. SketchView::SketchView(VFrame &f, DemoAppView *parent)
  30.     : VMdiView("SketchIcon", f, (VWindow *) parent, StyleBorder | StyleTitle | StyleCloseBox | StyleSizable)
  31. {
  32.     mainWin = parent;
  33.  
  34.     setTitle("C++/Views Sketch Pad Example");
  35.  
  36.     /* create a port for graphics output */
  37.     aPort = new VPort(this);
  38.     aPen = new VPen(BLACK);
  39.  
  40.     aPort->usePen(aPen);
  41.  
  42.     /* create a color select control */
  43.     colorBox = new ColorControl(VFrame(0, 0, 120, 50), this, StyleBorder);
  44.     colorBox->uponClick(this, methodOf(SketchView, newColor));
  45.  
  46.     /* create a point array */
  47.     points = new VPointArray(22);
  48.  
  49.     /* make sure the "About this Window" data is set up */
  50.     mainWin->setAboutNames("Sketch:About", "cvsketch.cpp");
  51. }
  52.  
  53. SketchView::~SketchView()
  54. {
  55.     if (aPort) {
  56.         aPort->free();
  57.     }
  58.  
  59.     if (aPen) {
  60.         aPen->free();
  61.     }
  62.  
  63.     delete points;
  64. }
  65.  
  66. boolean SketchView::free()
  67. {
  68.     delete this;
  69.     return(TRUE);
  70. }
  71.  
  72. boolean SketchView::paint()
  73. /*
  74.     Called by the window manager,
  75.     repaint the contents of our window
  76. */
  77. {
  78.     aPort->open();
  79.     aPort->drawLines(points);
  80.     aPort->close();
  81.     return(TRUE);
  82. }
  83.  
  84. boolean SketchView::close()
  85. /*
  86.     The user has closed the window.
  87.     Notify the main window so that it can update the main menu bar
  88. */
  89. {
  90.     mainWin->sketchView = 0;
  91.     mainWin->updateMenu();
  92.     return(FALSE);
  93. }
  94.  
  95. boolean SketchView::mouseDn(int mx, int my)
  96. /*
  97.     Called when a mouse button has been pressed down
  98.     within this window with the coordinates of the mouse.
  99. */
  100. {
  101.     notifier->captureMouseFor(this);
  102.     notifier->mouseTracking(TRUE);
  103.  
  104.     points->reset();
  105.     update();
  106.  
  107.     aPort->open();
  108.     aPort->moveTo(mx, my);
  109.     points->add(mx, my);
  110.  
  111.     return(TRUE);
  112. }
  113.  
  114. boolean SketchView::mouseMv(int mx, int my, int bStat)
  115. /*
  116.     Called if mouse tracking enabled, indicating the current 
  117.     position  and mouse button status.
  118.     If 'bStat' is TRUE then the mouse button is down, else FALSE. 
  119. */ 
  120. {
  121.     if (bStat) {
  122.         /* draw connecting line, add the point to the array */
  123.         aPort->lineTo(mx, my);
  124.         points->add(mx, my);
  125.         return(TRUE);
  126.     }
  127.     else {
  128.         return(FALSE);
  129.     }
  130. }
  131.  
  132. boolean SketchView::mouseUp(int mx, int my)
  133. /*
  134.     Called when a mouse button has been released
  135.     within this window with the coordinates of the mouse.
  136. */
  137. {
  138.     notifier->releaseCapture();
  139.     notifier->mouseTracking(FALSE);
  140.  
  141.     aPort->close();
  142.     update();
  143.  
  144.     return(TRUE);
  145. }
  146.  
  147. boolean SketchView::newColor()
  148. /*
  149.     New color selected in the color select control
  150. */
  151. {
  152.     if (aPen) {
  153.         aPen->color(colorBox->getColor());
  154.         update();
  155.     }
  156.  
  157.     return(TRUE);
  158. }
  159.  
  160. boolean SketchView::givenFocus()
  161. /*
  162.     Our window has just been given input focus
  163. */
  164. {
  165.     /* set the data for the About this Window dialog */
  166.     mainWin->setAboutNames("Sketch:About", "cvsketch.cpp");
  167.  
  168.     /* carry on with default window behavior, return FALSE */
  169.     return(FALSE);
  170. }
  171.  
  172.